package com.atguigu.upp.service;

import com.atguigu.upp.bean.TagInfo;
import com.atguigu.upp.bean.TaskInfo;
import com.atguigu.upp.bean.TaskTagRule;
import com.atguigu.upp.mapper.TagInfoMapper;
import com.atguigu.upp.mapper.TaskInfoMapper;
import com.atguigu.upp.mapper.TaskTagRuleMapper;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * Created by Smexy on 2022/11/30
 */
public class MySQLDBService
{
    private TagInfoMapper tagInfoMapper;
    private TaskInfoMapper taskInfoMapper;
    private TaskTagRuleMapper taskTagRuleMapper;

    public MySQLDBService(SqlSession session){
        this.tagInfoMapper = session.getMapper(TagInfoMapper.class);
        this.taskInfoMapper = session.getMapper(TaskInfoMapper.class);
        this.taskTagRuleMapper = session.getMapper(TaskTagRuleMapper.class);
    }

    public List<TagInfo> getTagInfoExecute(){
        return tagInfoMapper.getTagInfoExecute();
    }

    public void validId(Long id){
        if (id <= 0 && id != null){
            throw new RuntimeException("id非法!");
        }
    }

    public TagInfo getTagInfoByTaskId(Long id){
        validId(id);
        return tagInfoMapper.getTagInfoByTaskId(id);
    }

    public TaskInfo getTaskByTaskId(Long id){
        validId(id);
        return taskInfoMapper.getTaskById(id);
    }

    public List<TaskTagRule> getRulesByTaskId(Long id){
        validId(id);
        return taskTagRuleMapper.getTaskTagRulesByTaskId(id);
    }
}
